import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {Hero} from './hero';
import {HeroService} from './hero.service';

@Component({
  selector: 'app-my-heroes',
  templateUrl: './heroes.component.html',
  styleUrls: ['./heroes.component.css'],
  providers: [],
})
export class HeroesComponent implements OnInit {
  title = '查看';
  selectHero: Hero;
  heroes: Hero[];

  onSelect(hero: Hero): void {
    this.selectHero = hero;
  }

  getHeroes(): void {
    this.heroService.getHeroes().then(heros => {
      this.heroes = heros;
    });
  }

  gotoDetail(): void {
    this.router.navigate(['/detail', this.selectHero.id]);
  }

  constructor( private router: Router, private heroService: HeroService) {
  }

  ngOnInit(): void {
    this.getHeroes();
  }
}
